package com.yidu.action;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.common.Pages;
import com.yidu.common.Tools;
import com.yidu.domain.ListenQualityTestingDetail;
import com.yidu.service.ListenQualityTestingDetailService;

/**
 * @title 质检明细Controller类 
 * @author 江宇
 * @dateTime 2019年1月14日
 */
@Controller
@RequestMapping("/listenQualityTestingDetail")
public class ListenQualityTestingDetailController {
	@Resource
	ListenQualityTestingDetailService listenQualityTestingDetailService;
	
	/** 
	 * @title 增加质检明细
	 * @param ListenQualityTesting
	 * @return int
	 * @author 江宇
	 * @dateTime 2018年12月23日
	 * @versions 1.0
	 */
	@RequestMapping("addQualityTestingDetail")
	@ResponseBody
	
	public int addQualityTestingDetail(String detailText,String qtId){
		return listenQualityTestingDetailService.addQualityTestingDetail(detailText,qtId);
	}
	
	/**
     * @title 查询质检明细
     * @param Map
     * @return List
     * @author 江宇
     * @dateTime 2018年12月23日
     * @versions 1.0
     */
	@RequestMapping("findQualityTestingDetail")
	@ResponseBody
	
	public Map<String, Object> findQualityTestingDetail(ListenQualityTestingDetail qtd){
		Map<String, Object> map=new HashMap<>();
		
		//如果质检ID不为空赋值
		if(!Tools.isEmpty(qtd.getQtId())) {
			map.put("qtId", qtd.getQtId());
		}
		
		 
		 //如果前台传来的页数和行数不为空赋值
		if(qtd.getPage()!=null && qtd.getLimit()!=null) {
			Pages page=new Pages();
			page.setCurPage(qtd.getPage());
			page.setMaxResult(qtd.getLimit());
			
			map.put("firstRows", page.getFirstRows());
			map.put("maxResult", page.getMaxResult());
		}
		
		
		//调用查询质检明细的方法
		List<ListenQualityTestingDetail> list=listenQualityTestingDetailService.findQualityTestingDetail(map);
		//创建质检明细List集合
		List<ListenQualityTestingDetail> qtdList=new ArrayList<>();
		//循环查询的质检明细List
		for (ListenQualityTestingDetail listenQualityTestingDetail : list) {
			//创建质检明细类对象
			ListenQualityTestingDetail qtd2=new ListenQualityTestingDetail();
			//赋值
			BeanUtils.copyProperties(listenQualityTestingDetail, qtd2);
			//时间转换
			qtd2.setStringOpenTime(Tools.SDF_TIME.format(listenQualityTestingDetail.getOpenTime()));
			qtdList.add(qtd2);
		}
		//调用查询质检明细行数的方法
		int rows=listenQualityTestingDetailService.findQualityTestingDetailCount(map);
		
		Map<String, Object> layuiMap=new HashMap<>();
		
		layuiMap.put("code", 0);
		layuiMap.put("msg", "");
		layuiMap.put("count",rows);
		//将list放入map中
		layuiMap.put("data", qtdList);
		return layuiMap;
	}
}

